//
//  HomeJoinCell.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/24.
//

#import "HomeJoinCell.h"

@interface HomeJoinCell()
@property (nonatomic,strong) UILabel * nameLabel;
@property (nonatomic,strong) UIButton * enterbtn;
@end

@implementation HomeJoinCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];   
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(30 * FMScaleX);
        make.centerY.equalTo(@0);
    }];
    
    [self.contentView addSubview:self.enterbtn];
    [_enterbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(92 * FMScaleX, 30 * FMScaleX));
        make.centerY.equalTo(@0);
        make.right.mas_offset(-30 * FMScaleX);
    }];
}

-(void)setInfoModel:(DeviceInfo *)infoModel{
    
    self.nameLabel.text = infoModel.peripheralName;
    @WeakObj(self)
    [BCLRingManager.shared getCurrentDeviceWithCompletion:^(DeviceInfo * _Nullable device) {
        @StrongObj(self)
        self.enterbtn.selected = [device.uuidString isEqual:infoModel.uuidString];
    }];
}

-(UILabel *)nameLabel{
    
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = Regular(20);
        _nameLabel.textColor = RDRGB(0xB6904A);
    }
    return _nameLabel;
}
-(UIButton *)enterbtn{
    
    if (!_enterbtn) {
        _enterbtn = [[UIButton alloc]init];
        [_enterbtn setBackgroundImage:[UIImage imageNamed:@"Home_join_icon_no"] forState:UIControlStateNormal];
        [_enterbtn setBackgroundImage:[UIImage imageNamed:@"Home_join_icon_sel"] forState:UIControlStateSelected];
        [_enterbtn setTitle:@"连接设备" forState:UIControlStateNormal];
        [_enterbtn setTitle:@"断开连接" forState:UIControlStateSelected];
        [_enterbtn setTitleColor:RDRGB(0xB6904A) forState:UIControlStateNormal];
        [_enterbtn setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        _enterbtn.userInteractionEnabled = NO;
        _enterbtn.titleLabel.font = Regular(13 * FMScaleX);
    }
    return _enterbtn;
}
@end
